package com.jiang.action;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@SuppressWarnings("serial")
public class DMIDemoAction extends ActionSupport {

	public String add(){
		
		System.out.println("增加方法!");
		return null;
	}
	
	public String rm(){
		System.out.println("删除方法");
		return null;
	}
	
	public String update(){
		System.out.println("修改方法");
		return NONE;
	}
	
	public void list(){
		// 设置响应的编码格式
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("UTF-8");// 不设置则返回到页面上的中文乱码
		response.setContentType("text/html");
		JSONArray jsonArr = new JSONArray();
		for(int i=0;i<10;i++){ // 发送十条新闻消息
			JSONObject obj = new JSONObject();
			obj.put("number", "100"+i);
			obj.put("title", "范冰冰"+i);
			jsonArr.add(obj);
		}
		try {
			response.getWriter().write(jsonArr.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		System.out.println("查询方法!");
	}
	
}
